package com.ccl.iot.publics;import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.ccl.iot.template.ActivityDialog;


public class ActivityProgressDialog extends ActivityDialog {
	public static final int KSTYLE_HORIZONTAL = LinearLayout.HORIZONTAL;
	public static final int KSTYLE_VERTICAL = LinearLayout.VERTICAL;
	
	public static final String KEXTRA_NAME_STYLE = "Style";
	public static final String KEXTRA_NAME_MESSAGE = "Message";
	
	public static void Show(Context aContext, int aStyle, Object aMessage, DialogInterface aInterface){
		Bundle tBundle = ActivityDialog.ObtainBundle(true, false);
		
		tBundle.putInt(KEXTRA_NAME_STYLE, aStyle);
		
		if (aMessage != null){
			tBundle.putString(KEXTRA_NAME_MESSAGE, ActivityDialog.GetString(aContext, aMessage));
		}
		
		ActivityDialog.Show(aContext, ActivityProgressDialog.class, tBundle, aInterface);
	}
	
	public static void Show(Context aContext, Object aMessage, DialogInterface aInterface){
		Show(aContext, aMessage, aInterface);
	}
	
	public static void Show(Context aContext, Object aMessage){
		Show(aContext, aMessage, null);
	}

	
	private int iStyle = KSTYLE_VERTICAL;
	private String iMessageText = null;
	
	private LinearLayout iFrame = null;
	
	private ProgressBar iProgress = null;
	private TextView iMessage = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		initialize();
		
		initializeLayout();
	}
	
	private void initialize(){
		iStyle = this.getIntent().getIntExtra(KEXTRA_NAME_STYLE, KSTYLE_VERTICAL);
		iMessageText = getString(KEXTRA_NAME_MESSAGE);
	}
	
	private void initializeLayout(){
		LinearLayout.LayoutParams tParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
		
		if (iStyle == KSTYLE_VERTICAL){
			tParams.gravity = Gravity.CENTER_HORIZONTAL;
		}else{
			tParams.gravity = Gravity.CENTER_VERTICAL;
		}
		
		iFrame = new LinearLayout(this);
		iFrame.setPadding(10, 10, 10, 10);
		iFrame.setOrientation(iStyle);
		
		iProgress = new ProgressBar(this, null, android.R.attr.progressBarStyleLarge);
		iFrame.addView(iProgress, tParams);
		
		iMessage = new TextView(this);
		iFrame.addView(iMessage, tParams);
		
		iMessage.setText(iMessageText);
		
		super.setContentView(iFrame, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
	}
	
	public void setMessage(String aMessage){
		iMessageText = aMessage;
		
		iMessage.setText(aMessage);
	}
	
	public void setMessage(int aMessage){
		setMessage(GetString(this, aMessage));
	}
}
